package com.third.share;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

import com.third.login.R;
import com.third.login.ThirdLoginPlatform;
import com.third.share.view.ThirdShareItem;

/**
 * Created by Administrator on 2017-11-07.
 */

public abstract class ThirdShareOperatorBase {
    protected View mMainView;
    protected Context mContext;
    protected ThirdShareItem tvQQShare;
    protected ThirdShareItem tvQZoneShare;
    protected ThirdShareItem tvWechatShare;
    protected ThirdShareItem tvWxcircleShare;
    protected ThirdShareItem tvSinaShare;
    protected ShareData mShareData;
    protected ThirdShareBase mQQShare;
    protected ThirdShareBase mWeiXinShare;
    protected ThirdShareBase mSinaShare;
    protected int mSelectIndex  = 0;
    protected int[] mPicIdList ={R.mipmap.socialize_click_wxcircle,R.mipmap.socialize_click_wxchat,
                        R.mipmap.socialize_click_sina,R.mipmap.socialize_click_qq,R.mipmap.socialize_click_qzone};

    protected int[] mSelectPicIdList ={R.mipmap.socialize_wxcircle,R.mipmap.socialize_wxchat,
            R.mipmap.socialize_sina,R.mipmap.socialize_qq,R.mipmap.socialize_qzone};

    protected boolean[] mSelectList = {true,false,false,false,false};
    protected ThirdShareItem mSelectThirdShareItem;
    public ThirdShareOperatorBase(Context context, View mainView){
        mContext = context;
        mMainView = mainView;
    }

    public void setOnClickListener(View.OnClickListener listener){
        tvQQShare.setOnClickListener(listener);
        tvQZoneShare.setOnClickListener(listener);
        tvWechatShare.setOnClickListener(listener);
        tvWxcircleShare.setOnClickListener(listener);
        tvSinaShare.setOnClickListener(listener);
    }
    public void onCreate(Bundle bundle){
        tvQQShare = (ThirdShareItem)mMainView.findViewById(R.id.tvQQShare);
        tvQZoneShare = (ThirdShareItem)mMainView.findViewById(R.id.tvQZoneShare);
        tvWechatShare = (ThirdShareItem)mMainView.findViewById(R.id.tvWechatShare);
        tvWxcircleShare = (ThirdShareItem)mMainView.findViewById(R.id.tvWxcircleShare);
        tvSinaShare = (ThirdShareItem)mMainView.findViewById(R.id.tvSinaShare);
       // mSelectThirdShareItem = tvWxcircleShare;
    }


    public void onClick(View view){
        int id = view.getId();
        ThirdLoginPlatform platform = null;
        if(id != R.id.btnCancel ) {
            if (mSelectThirdShareItem != view) {
                if (mSelectThirdShareItem != null) {
                    mSelectThirdShareItem.setImagePic(mPicIdList[mSelectIndex]);
                    mSelectList[mSelectIndex] = false;
                }
            }
        }
        if(id == R.id.tvWxcircleShare){
            mSelectIndex = 0;
            platform = ThirdLoginPlatform.WEIXIN_CIRCLE;
        }else if(id == R.id.tvWechatShare){
            mSelectIndex = 1;
            platform = ThirdLoginPlatform.WEIXIN;
        }else if(id == R.id.tvSinaShare){
            mSelectIndex = 2;
            platform = ThirdLoginPlatform.SINA;
        }else if(id == R.id.tvQQShare){
            mSelectIndex = 3;
            platform = ThirdLoginPlatform.QQ;
        }else if(id == R.id.tvQZoneShare){
            mSelectIndex = 4;
            platform = ThirdLoginPlatform.QZONE;
        }else if(id == R.id.btnCancel){
        }

        if(id != R.id.btnCancel ){
            if(mSelectThirdShareItem != view){
                ThirdShareItem item = (ThirdShareItem)view;
                item.setImagePic(mSelectPicIdList[mSelectIndex]);
                mSelectThirdShareItem = item;
                mSelectList[mSelectIndex] = true;
            }else{
                mSelectList[mSelectIndex] =  !mSelectList[mSelectIndex];
                clickSameView(view);
            }
        }
        if(platform != null){
            shareOperator(platform);
        }
    }

    protected void clickSameView(View view){

    }
    public void setShareData( ShareData shareData){
        mShareData = shareData;
    }
    protected  abstract void shareOperator(ThirdLoginPlatform platform);
}
